<?php

namespace IMT\EventBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;


class CallController extends Controller
{
    public function indexAction($id)
    {
    	$emTask = $this->container->get('imt_event.call_manager');
    	$securityContext = $this->get('security.context');
    	$user = $securityContext->getToken()->getUser();
    	
    	if($id == 0){
    		$event = $emTask->createEvent();
    	} else {
    		$event = $emTask->findEventBy(array('id' => $id));
    		 
    		if(!$event)
    			throw $this->createNotFoundException('L\'appel téléphonique recherché n\'existe pas');
    	}
    	
    	$defaultConfig = $emTask->getDefaultConfig();
    	
    	$jsonConfig = $emTask->convertConfigToJSON($defaultConfig);
    	
       	return $this->render('IMTEventBundle:Call:index.html.twig', array(
       		'event_entity' => $event,
       		'event_json' => $event->convertEventToJson(),
       		'em_config' => $defaultConfig,
       		'em_config_json' => $jsonConfig
       	)); // index2 => event
    }
}


